package dispatcher.group.gui.listener;

import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

import state.Globals;

import dispatcher.person.gui.PersonDispatcherView;

/**
 * This class waits for an PersonDispatcherPreInitConditionEvent to appear then starts 
 * a connection from the PersonDispatcherGUIObserverThread to the PersonDispatcher
 * @author Caleb
 *
 */
public class PersonDispatcherPreInitConditionListener implements ActionListener {

	/**
	 * This method will start a connection to the PersonDispatcher
	 */
	@Override
	public void actionPerformed(ActionEvent arg0) {
		if (arg0 instanceof PersonDispatcherPreInitConditionEvent){
			PersonDispatcherPreInitConditionEvent event = (PersonDispatcherPreInitConditionEvent)arg0;
			if (event.getAddress() == null){
				Globals.getLogger().log("PersonDispatcher Address is null", this.getClass().getName(), "actionPerformed");
				return;
			}
			// Starts connection to PersonDispatcher
			PersonDispatcherView.getInstance().connectToServer(event.getAddress(), event.getPort());
		}
	}

}
